/**
 * Alipay.com Inc.
 * Copyright (c) 2004-2021 All Rights Reserved.
 */
package com.itcorey.interview.thread;

/**
 * @Description
 * @author xuyp
 * @version $Id: VolatileDemo.java, v 0.1 2021-02-19 17:23 zhi.huangcz Exp $$
 */
public class VolatileDemo {
    public static void main(String[] args) {
        VolatileCorey corey = new VolatileCorey();
        corey.start();
        for (; ;){
            if (corey.isFlag()){
                System.out.println("有点东西......");
            }
        }

    }

   static class VolatileCorey extends Thread {
        private volatile boolean flag = false;

        public boolean isFlag(){
            return flag;
        }

        @Override
        public void run() {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            flag = true;
            System.out.println("flag="+flag);
        }
    }

}